#include "../app_common.h"

int* inorderTraversal(struct TreeNode* root, int* returnSize)
{
    TreeNode* current = root;
    struct TreeNode* stack[100];   // 假设最大深度不超过100，实际应用中应该使用动态数组或链表
    int* val_stack = (int *)malloc(100 * sizeof(int));
    int val_index = 0;
    int top = -1;

    if(returnSize == NULL) {
        return NULL;
    }

    if(root == NULL) {
        *returnSize = 0;
        return NULL;
    }

    while (current != NULL || top != -1) {
        while (current != NULL) {
            stack[++top] = current;   // 将节点压入栈
            current      = current->left;
        }

        current = stack[top--];        // 弹出栈顶元素
        printf("%d ", current->val);   // 访问节点
        val_stack[val_index++] = current->val;

        current = current->right;   // 转向右子树
    }
    
    *returnSize = val_index;
    return val_stack;
}

int main(int argc, char* argv[])
{
    // inorderTraversal();
    return 0;
}
